package com.kingsoft.dc.khaos.module.spark.metadata.source

import org.json4s.JsonAST.JObject



/**
 * Created by chengguangqing on 2019/6/2.
 */
case class ExtractInfo(id: String = null,
                       name: String = null,
                       clazz: String = null,
                       engine: String = null,
                       clazz_type: String = null,
                       strategy: ExtractStrategy) {}

case class ExtractStrategy(clazz: String = null,
                           config: JObject = null) {}

case class HdfsConfig(db_name: String = "",
                      table_name: String = "",
                      hdfs_sub_path: Option[String],
                      filter: String = null,
                      advanced_options: HdfsAdvancedOption,
                      extender: ExtenderInfo = null,
                      extract_fields: List[ExtractOption] = List()
                     )

case class HdfsAdvancedOption(ignore_abnormal: Option[IgnoreAbnormal] = Option(IgnoreAbnormal(on_off = Option(false)))
                             )

case class HdfsCheckConfig(input_dat_path: String, //输入路径
                           input_dat_name: String, //文件名
                           input_ddl_path: String, //ddl扩展路径
                           input_xml_path: String, //ddl扩展路径
                           output_path: String, //输出文件路径
                           source_encoding: String //输入数据文件编码
                          )

case class NewTechCheckConfig(dest_encoding: String,
                              spliter_code: String = null,
                              reject_percent: Float //
                             )

case class MySQLConfig(db_name: String = null,
                       table_name: String = null,
                       filter: String = null,
                       shardingSwitch: Boolean = false,
                       shardingSourceList: List[ShardingSourceInfo] = List(),
                       shardingDb: String = null,
                       shardingDbKey: String = null,
                       shardingDbType: String = null,
                       shardingDbValue: String = null,
                       shardingTable: String = null,
                       shardingTableKey: String = null,
                       shardingTableType: String = null,
                       shardingTableValue: String = null,
                       advanced_options: RdbmsAdvancedOption,
                       extender: ExtenderInfo = null,
                       extract_fields: List[ExtractFieldInfo] = List()
                      )

case class SQLServerConfig(db_name: String = null,
                           table_name: String = null,
                           filter: String = null,
                           advanced_options: RdbmsAdvancedOption,
                           extender: ExtenderInfo = null,
                           extract_fields: List[ExtractFieldInfo] = List()
                          )

case class OracleConfig(db_name: String = null,
                        table_name: String = null,
                        filter: String = null,
                        shardingSwitch: Boolean = false,
                        shardingSourceList: List[ShardingSourceInfo] = List(),
                        shardingDb: String = null,
                        shardingDbKey: String = null,
                        shardingDbType: String = null,
                        shardingDbValue: String = null,
                        shardingTable: String = null,
                        shardingTableKey: String = null,
                        shardingTableType: String = null,
                        shardingTableValue: String = null,
                        advanced_options: RdbmsAdvancedOption,
                        extender: ExtenderInfo = null,
                        extract_fields: List[ExtractFieldInfo] = List()
                       )

case class ShardingSourceInfo(
                               dsName: String = null,
                               dsId: String = null,
                               dataType: String = null
                             )

case class RdbmsAdvancedOption(split_mode: Option[SplitOption])

case class SplitOption(on_off: Boolean = false,
                       split_options: Option[String] = Option(""),
                       split_field: String = null,
                       split_nums: String = null)

case class ExtractOption(field: String = null,
                         data_type: String = null,
                         option: List[String] = null
                        ) {}

/*
  hive
 */
case class HiveSourceConfig(db_name: String = "",
                            table_name: String = "",
                            filter: String = "",
                            advanced_options: Any,
                            extender: ExtenderInfo = null,
                            extract_fields: List[ExtractFieldInfo] = null
                           )

//case class HiveSourceConfig(db_name: String = "",
//                            table_name: String = "",
//                            filter: String = "",
//                            advanced_options: Map[String, Any],
//                            extender: ExtenderInfo = null,
//                            extract_fields: List[ExtractFieldInfo] = null
//                           )

case class ExtenderInfo(auth: ExtendedAuth = null,
                        meta: ExtendedMeta = null)

case class ExtendedAuth(clazz: String = "",
                        params: JObject = null)

case class ExtendedMeta(clazz: String = "",
                        params: JObject = null)

case class ExtendedAuthParams(ds_type: String = "",
                              ds_id: String = "",
                              ds_name: String = "",
                              project_id: String = "",
                              defaultDs: Option[Boolean])

case class ExtendedMetaParams(ds_type: String = "",
                              ds_id: String = "",
                              ds_name: String = "",
                              project_id: String = "",
                              defaultDs: Option[Boolean])

case class ExtractFieldInfo(field: String = "",
                            data_type: String = "",
                            length: Option[String],
                            regex: Option[String])

/*
  hbase
 */
case class HBaseConfig(db_name: String = null,
                       table_name: String = null,
                       filter: String = null,
                       advanced_options: HBaseAdvancedOption = null,
                       extender: ExtenderInfo = null,
                       extract_fields: List[ExtractFieldInfo] = List()
                      )

case class HBaseAdvancedOption(data_version: Option[HBaseDataVersion],
                               rowkey_range: Option[HBaseRowkeyRange]
                              )

case class HBaseDataVersion(on_off: Option[Boolean] = null,
                            max_versions: Option[Int] = null,
                            timestamp: Option[String] = null,
                            min_timestamp: Option[String] = null,
                            max_timestamp: Option[String] = null
                           )

case class HBaseRowkeyRange(on_off: Option[Boolean] = null,
                            row_start: Option[String] = null,
                            row_end: Option[String] = null
                           )


/*
cos
*/
case class CosSourceConfig(db_name: String = "",
                           table_name: String = "",
                           file_name: Option[String],
                           filter: String = "",
                           skip_head: String = "",
                           advanced_options: CosAdvancedOption,
                           extender: ExtenderInfo = null,
                           extract_fields: List[ExtractFieldInfo] = null)

case class CosAdvancedOption(ignore_abnormal: Option[IgnoreAbnormal] = Option(IgnoreAbnormal(on_off = Option(false))),
                             fixed_read_increment: Option[FixedReadIncrement],
                             replace_content: Option[CosReplaceContent]
                            )

case class FixedReadIncrement(on_off: Option[Boolean] = Option(false),
                              value: Option[String]
                             )

case class CosReplaceContent(on_off: Option[Boolean] = Option(false),
                             detailed: Option[List[CosReplaceContentInfo]]
                            )

case class CosReplaceContentInfo(source: String = "",
                                 target: String = "",
                                 replace_type: String = "",
                                 scope: String = "")

/*
  mpp
 */
case class MppSourceConfig(db_name: String = "",
                           table_name: String = "",
                           sub_table: Option[SubTabelInfo],
                           filter: String = "",
                           advanced_options: Map[String, Any],
                           extender: ExtenderInfo = null,
                           extract_fields: List[ExtractFieldInfo] = null
                          )

case class SubTabelInfo(on_off: String = "false",
                        suffix: String = "")

//db信息
case class DbInfo(ds_id: String = "",
                  ds_type: String = "",
                  ds_name: String = "",
                  db_name: String = "",
                  table_name: String = "",
                  project_id: String = ""
                 ) {}

/*
InfluxDB
 */
case class InfluxSourceConfig(db_name: String = "",
                              table_name: String = "",
                              filter: String = "",
                              advanced_options: Map[String, Any],
                              extender: ExtenderInfo = null,
                              extract_fields: List[InfluxExtractFieldInfo] = null)

case class InfluxExtractFieldInfo(field: String = "",
                                  data_type: String = "",
                                  length: Option[String],
                                  regex: Option[String])

/*
PGsql
 */
case class PGSqlSourceConfig(db_name: String = "",
                             table_name: String = "",
                             sub_table: Option[SubTabelInfo],
                             filter: String = "",
                             advanced_options: Map[String, Any],
                             extender: ExtenderInfo = null,
                             extract_fields: List[ExtractFieldInfo] = null)

/*
GreenPlumDB
 */
case class GreenPlumSourceConfig(db_name: String = "",
                                 table_name: String = "",
                                 sub_table: Option[SubTabelInfo],
                                 filter: String = "",
                                 advanced_options: Map[String, Any],
                                 extender: ExtenderInfo = null,
                                 extract_fields: List[ExtractFieldInfo] = null)

/*
HAWQ
 */
case class HAWQSourceConfig(db_name: String = "",
                            table_name: String = "",
                            sub_table: Option[SubTabelInfo],
                            filter: String = "",
                            advanced_options: Map[String, Any],
                            extender: ExtenderInfo = null,
                            extract_fields: List[ExtractFieldInfo] = null)

/*
ks3
 * */
case class Ks3Config(db_name: String = "",
                     table_name: String = "",
                     read_path_mode: Ks3ReadPathMode = null,
                     compression_type: Option[String] = null,
                     filter: String = "",
                     skip_head: String = "",
                     advanced_options: Ks3AdvancedOption,
                     extender: ExtenderInfo = null,
                     extract_fields: List[ExtractFieldInfo] = null
                    )

case class Ks3ReadPathMode(path_type: Option[String] = null,
                           file_name: Option[String] = null,
                           folder_regex_path: Option[String] = null,
                           folder_regex_range_type: Option[String] = null,
                           folder_regex_range_ruler: Option[String] = null,
                           folder_regex_range_num: Option[String] = null
                          )

case class Ks3AdvancedOption(ignore_abnormal: Option[IgnoreAbnormal] = Option(IgnoreAbnormal(on_off = Option(false))),
                             fixed_read_increment: Option[Ks3FixedReadIncrement],
                             replace_content: Option[Ks3ReplaceContent]
                            )

case class Ks3FixedReadIncrement(on_off: Option[Boolean] = Option(false),
                                 value: Option[String]
                                )

case class Ks3ReplaceContent(on_off: Option[Boolean] = Option(false),
                             detailed: Option[List[Ks3ReplaceContentInfo]]
                            )

case class Ks3ReplaceContentInfo(source: String = "",
                                 target: String = "",
                                 replace_type: String = "",
                                 scope: String = "")


/*
Kafka
 */
case class KafkaSourceConfig(db_name: String = "",
                             table_name: String = "",
                             time_offset_m: String = "",
                             time_offset_s: String = "",
                             strat_offset: Option[Boolean] = Option(false),
                             reset_config: Option[ResetConf] = null,
                             incr_sync: Option[Boolean] = Option(true),
                             filter: Option[String],
                             advanced_options: KafkaAdvancedOptions,
                             extender: ExtenderInfo = null,
                             extract_fields: List[ExtractFieldInfo] = null)

case class ResetConf(reset: Option[String] = Option(""),
                     timestamp: Option[String] = Option(""))

case class KafkaAdvancedOptions(var ignore_abnormal: Option[IgnoreAbnormal] = Option(IgnoreAbnormal(on_off = Option(false))))


/*
* sql
 */

case class SqlSourceConfig(db_name: String = "",
                           table_name: String = "",
                           sql: String = "",
                           advanced_option: Any,
                           extender: ExtenderInfo = null,
                           extract_fields: List[ExtractFieldInfo])

case class SqlExtendedAuthParams(ds_type: String = "",
                                 ds_id: String = "",
                                 ds_name: String = "",
                                 project_name: String = ""
                                )

/*
    redis
 */
case class RedisSourceConfig(db_name: Option[String] = null,
                             table_name: String,
                             value_mode: RedisValueMode = null,
                             filter: String = "",
                             advanced_options: RedisAdvancedOption = null,
                             extender: ExtenderInfo = null,
                             extract_fields: List[ExtractFieldInfo] = List()
                            )

case class RedisAdvancedOption(var ignore_abnormal: Option[IgnoreAbnormal] = Option(IgnoreAbnormal(on_off = Option(false))),
                               delete_keys: Option[DeleteKeys] = Option(DeleteKeys(on_off = Option(false)))
                              )

case class DeleteKeys(on_off: Option[Boolean] = Option(false)
                     )

case class IgnoreAbnormal(on_off: Option[Boolean] = Option(false)
                         )


case class RedisValueMode(`type`: Option[String] = null,
                          write_mode: Option[String] = null,
                          value_delimiter: Option[String] = null
                         )

/*
  hive
 */
case class EsSourceConfig(db_name: String = "",
                          table_name: String = "",
                          filter: String ,
                          advanced_options: Map[String, Any],
                          extender: ExtenderInfo = null,
                          extract_fields: List[ExtractFieldInfo] = null
                         )
